/*
function nextInput(obj){

    var vallen=obj.val().length;
    var valid=obj.attr("id");
    console.log(vallen);
    var parkno1=$("#parkno1").val();
    var parkno2=$("#parkno2").val();
    var parkno3=$("#parkno3").val();
    var parkno4=$("#parkno4").val();
    var parkno5=$("#parkno5").val();
    var parkno6=$("#parkno6").val();
    if(vallen>0){
      if(obj.attr("id")=="parkno1"){
       /* if(parkno1&&parkno2&&parkno3&&parkno4&&parkno5&&parkno6){
          obj.blur();
        }
        else{
    	  console.log(obj.attr("id"))
          $("#parkno2").focus();
        //}
      }
      if(obj.attr("id")=="parkno2"){
          $("#parkno3").focus();
      }
      if(obj.attr("id")=="parkno3"){
          $("#parkno4").focus();
      }
      if(obj.attr("id")=="parkno4"){
          $("#parkno5").focus();
      }
      if(obj.attr("id")=="parkno5"){
          $("#parkno6").focus();
      }
      if(obj.attr("id")=="parkno6"){
        $("#parkno6").blur();
      }
    }
*/
	function nextInput(obj){
	 var vallen=0;
	 if(obj!=undefined&&obj.val()){
		 vallen =obj.val().length;
	 }
	 //var vallen=obj.val().length;
	 if(vallen>0){
	  if(obj.attr("id")=="parkno1"){
	    $("#parkno2").focus();
	    var that=document.getElementById('parkno2');
	    setTimeout(function(){
	   	 var start = that.selectionStart,end = that.selectionEnd;
	   	 console.log('2');

	   	 that.setSelectionRange(0,1);
	   	 if(start==1){
	   	   $(that).attr("cov","true");
	   	 }
	   	},40);
	  }
	  if(obj.attr("id")=="parkno2"){
	    $("#parkno3").focus();
	    var that=document.getElementById('parkno3');
	    setTimeout(function(){
	   	 var start = that.selectionStart,end = that.selectionEnd;
	   	 console.log('3');
	   	 that.setSelectionRange(0,1);
	   	 if(start==1){
	   	   $(that).attr("cov","true");
	   	 }
	   	},40);
	  }
	  if(obj.attr("id")=="parkno3"){
	    $("#parkno4").focus();
	    var that=document.getElementById('parkno4');
	    setTimeout(function(){
	   	 var start = that.selectionStart,end = that.selectionEnd;
	   	console.log('4');

	   	 that.setSelectionRange(0,1);
	   	 if(start==1){
	   	   $(that).attr("cov","true");
	   	 }
	   	},40);
	  }
	  if(obj.attr("id")=="parkno4"){
	    $("#parkno5").focus();
	    var that=document.getElementById('parkno5');
	    setTimeout(function(){
	   	 var start = that.selectionStart,end = that.selectionEnd;
	   	 console.log('5');
	   	 that.setSelectionRange(0,1);
	   	 if(start==1){
	   	   $(that).attr("cov","true");
	   	 }
	   	},40);
	  }
	  if(obj.attr("id")=="parkno5"){
	    $("#parkno6").focus();
	    var that=document.getElementById('parkno6');
	    setTimeout(function(){
	   	 var start = that.selectionStart,end = that.selectionEnd;
	   	 console.log('6');

	   	 that.setSelectionRange(0,1);
	   	 if(start==1){
	   	   $(that).attr("cov","true");
	   	 }
	   	},40);
	  }
	  if(obj.attr("id")=="parkno6"){
		  $("#parkno6").blur();
	      $(".buttoncenter").focus();
	  }
	 }
	}


/** trigger for parkno input change, when user have input full parking no,
    connect with server
**/
function getParkingInfo(obj){

  var parkno1=$("#parkno1").val();
  var parkno2=$("#parkno2").val();
  var parkno3=$("#parkno3").val();
  var parkno4=$("#parkno4").val();
  var parkno5=$("#parkno5").val();
  var parkno6=$("#parkno6").val();
  if(parkno1&&parkno2&&parkno3&&parkno4&&parkno5&&parkno6){
    var parkno=parkno1+parkno2+parkno3+parkno4+parkno5+parkno6;
    //演示情况区域编码写死，01厦门
    $.getJSON(parkUserServer.getParkUserSerReq(areaId,parkno),function(data){
      if(data.success==true){
        //popSucc(data.msg);
        if(data.obj.hour.toString().length==1){
          $("#hours").html("0"+data.obj.hour);
        }else{
          $("#hours").html(data.obj.hour);
        }
        if(data.obj.minute.toString().length==1){
	      $("#hours").html("0"+data.obj.minute);
	     }else{
	      $("#mints").html(data.obj.minute);
	    }
        $("#cost").html(" ￥"+data.obj.total);
        $("#totalFee").val(data.obj.total.toString());
        nextInput(obj);
      }else{
        //popFaild("用户未登录，请先登录或注册！");
    	  if(obj.attr("id")=="parkno1"){
    		  $("#parkno1").blur();
    	      $(".buttoncenter").focus();
    	  }
    	  if(obj.attr("id")=="parkno2"){
    		  $("#parkno2").blur();
    	      $(".buttoncenter").focus();
    	  }
    	  if(obj.attr("id")=="parkno3"){
    		  $("#parkno3").blur();
    	      $(".buttoncenter").focus();
    	  }
    	  if(obj.attr("id")=="parkno4"){
    		  $("#parkno5").blur();
    	      $(".buttoncenter").focus();
    	  }
    	  if(obj.attr("id")=="parkno5"){
    		  $("#parkno5").blur();
    	      $(".buttoncenter").focus();
    	  }
    	  if(obj.attr("id")=="parkno6"){
    		  $("#parkno6").blur();
    	      $(".buttoncenter").focus();
    	  }
        if (window.localStorage){
          var carman=localStorage.removeItem("loginInfo");
        }
        popChoice(data.msg,function(){$("#username").click()});
      }
    })
  }else{
	 nextInput(obj);
  }
}

/**
 comfirm order button validation function
 **/
 function comfirmOrderVal(){
   var spacialCarSite=localStorage.getItem("spacialCarSite");
//   if(spacialCarSite){
	   //如果是专属车位，则进入专属车位处理
	   
//   }else{
	   var parkno1=$("#parkno1").val();
	   var parkno2=$("#parkno2").val();
	   var parkno3=$("#parkno3").val();
	   var parkno4=$("#parkno4").val();
	   var parkno5=$("#parkno5").val();
	   var parkno6=$("#parkno6").val();
	   var phoneno=$("#username").html();
	   var parkno=parkno1+parkno2+parkno3+parkno4+parkno5+parkno6;
	   if(parkno==""){
	     popFaild("请输入泊车编号！");
	     return ;
	   }
	   /**
	   if(phoneno=="未登录"){
	     popChoice("用户未登录，请先登录或注册！",function(){$("#username").click()});
	     return ;
	   }
	**/
	   if (window.localStorage){
	    var carman=localStorage.getItem("loginInfo");
	    if(!carman){
	      popChoice("用户未登录，请先登录或注册！",function(){$("#username").click()});
	      return true;
	    }
	  }
	   if(parkno1&&parkno2&&parkno3&&parkno4&&parkno5&&parkno6){
	     var parkno=parkno1+parkno2+parkno3+parkno4+parkno5+parkno6;
	//     alert(createrOrderServer.getCreaterOrderReq($("#totalFee").val(),parkno,phoneno));
	     $.getJSON(createrOrderServer.getCreaterOrderReq($("#totalFee").val(),parkno,phoneno,areaId),function(data){
	       if(data.success==true){
	        //console.log(data);
	        //popSucc(data.msg);
	        $("#tdOrderNo").html(data.attributes.sysOrderNo);
	        $("#OrderLineName").html("");
	        $("#orderPakingNo").html(data.attributes.parkNo);
	        $("#orderParkingPrice").html("");
	        $("#orderParkingTime").html("");
	        $("#orderTime").html("");
	        $("#orderTotalFee").html("￥"+$("#totalFee").val());
	        //设置预付款单号
	        payPreId = data.attributes.prePayId;
	        goToComfirmOrder();
	        $("#comfirmO").click();
	       }else{
	         popFaild(data.msg);
	       }
	     });
	   }else{
		   popChoice("用户未登录，请先登录或注册！",function(){$("#username").click()});
		   return;
	   }
//   }
 }

function plusmint(){
  var mints=$("#mints").html();
  switch(mints){
    case '00':
      //$("#mints").html('30');
      if($("#hours").html()=='23'||$("#hours").html()=='00'){
        $("#mints").html('30');
        break;
      }
      if($("#hours").html()=='24'){
        $("#mints").html('00');
        $("#hourplus").trigger("click");
        break;
      }
      $("#mints").html('30');
      $("#hourplus").trigger("click");
      break;
    case '30':
      $("#mints").html('00');
      if($("#hours").html()=='23'){
        $("#hours").html('00');
        break;
      }
      $("#hourplus").click();
      break;
  }
}

function submint(){
  var mints=$("#mints").html();
  /**
  switch(mints){
    case '00':
      $("#mints").html('30');
      if($("#hours").html()=='00'){
        $("#hours").html('23');
        break;
      }
      $("#hoursub").trigger("click");
      break;
    case '30':
      $("#mints").html('00');
      if($("#hours").html()=='01'||$("#hours").html()=='00'){
        break;
      }
      $("#hoursub").click();
      break;
  }
  **/
  /**时间是00:00，按“-”，时间不应该变成23:30，保持00：00**/
  switch(mints){
    case '00':
      if($("#hours").html()=='00'){
        break;
      }
      $("#mints").html('30');
      $("#hoursub").trigger("click");
      break;
    case '30':
      $("#mints").html('00');
      if($("#hours").html()=='01'||$("#hours").html()=='00'){
        break;
      }
      $("#hoursub").click();
      break;
  }
}

function subhour(){
  var hours=$("#hours").html();
  switch(hours){
    case '00':
      if($("#mints").html()=='30'){
        $("#hours").html('23');
        break;
      }
      $("#hours").html('24');
      break;
    case '01':
      $("#hours").html('00');
      break;
    case '02':
      $("#hours").html('01');
      break;
    case '03':
      $("#hours").html('02');
      break;
    case '04':
      $("#hours").html('03');
      break;
    case '05':
      $("#hours").html('04');
      break;
    case '06':
      $("#hours").html('05');
      break;
    case '07':
      $("#hours").html('06');
      break;
    case '08':
      $("#hours").html('07');
      break;
    case '09':
      $("#hours").html('08');
      break;
    case '10':
      $("#hours").html('09');
      break;
    case '11':
      $("#hours").html('10');
      break;
    case '12':
      $("#hours").html('11');
      break;
    case '13':
      $("#hours").html('12');
      break;
    case '14':
      $("#hours").html('13');
      break;
    case '15':
      $("#hours").html('14');
      break;
    case '16':
      $("#hours").html('15');
      break;
    case '17':
      $("#hours").html('16');
      break;
    case '18':
      $("#hours").html('17');
      break;
    case '19':
      $("#hours").html('18');
      break;
    case '20':
      $("#hours").html('19');
      break;
    case '21':
      $("#hours").html('20');
      break;
    case '22':
      $("#hours").html('21');
      break;
    case '23':
      $("#hours").html('22');
      break;
    case '24':
      $("#hours").html('23');
      break;
  }
}

function plushour(){
  var hours=$("#hours").html();
  switch(hours){
    case '00':
      $("#hours").html('01');
      break;
    case '01':
      $("#hours").html('02');
      break;
    case '02':
      $("#hours").html('03');
      break;
    case '03':
      $("#hours").html('04');
      break;
    case '04':
      $("#hours").html('05');
      break;
    case '05':
      $("#hours").html('06');
      break;
    case '06':
      $("#hours").html('07');
      break;
    case '07':
      $("#hours").html('08');
      break;
    case '08':
      $("#hours").html('09');
      break;
    case '09':
      $("#hours").html('10');
      break;
    case '10':
      $("#hours").html('11');
      break;
    case '11':
      $("#hours").html('12');
      break;
    case '12':
      $("#hours").html('13');
      break;
    case '13':
      $("#hours").html('14');
      break;
    case '14':
      $("#hours").html('15');
      break;
    case '15':
      $("#hours").html('16');
      break;
    case '16':
      $("#hours").html('17');
      break;
    case '17':
      $("#hours").html('18');
      break;
    case '18':
      $("#hours").html('19');
      break;
    case '19':
      $("#hours").html('20');
      break;
    case '20':
      $("#hours").html('21');
      break;
    case '21':
      $("#hours").html('22');
      break;
    case '22':
      $("#hours").html('23');
      break;
    case '23':
      if($("#mints").html()=='30'){
        $("#hours").html('00');
      }else{
        $("#hours").html('24');
      }
      break;
    case '24':
      $("#hours").html('00');
      break;
  }
}


function vipOperation(type) {
	var parkNo = localStorage.getItem("parkNos");
	$.getJSON(vipOperationServer.vipOperation(areaId,parkNo,type),function(data){
	    if(data.success==true){
	      popSucc(data.msg);
	    }else{
	      popFaild(data.msg);
	    }
	  });
}
